package com.bawei.lib_storage.database.dao

import androidx.room.*
import com.bawei.lib_storage.database.entity.FavoriteVideoEntity

@Dao
interface FavoriteVideoDao {
    
    @Query("SELECT * FROM b_favorite_video WHERE userId = :userId ORDER BY collectTime DESC")
    fun getAllByUserId(userId: String): List<FavoriteVideoEntity>
    
    @Query("SELECT * FROM b_favorite_video WHERE videoId = :videoId AND userId = :userId LIMIT 1")
    fun getByVideoIdAndUserId(videoId: Int, userId: String): FavoriteVideoEntity?
    
    @Query("SELECT EXISTS(SELECT 1 FROM b_favorite_video WHERE videoId = :videoId AND userId = :userId)")
    fun isFavorite(videoId: Int, userId: String): Boolean
    
    @Insert
    fun insert(favoriteVideo: FavoriteVideoEntity)
    
    @Delete
    fun delete(favoriteVideo: FavoriteVideoEntity)
    
    @Query("DELETE FROM b_favorite_video WHERE videoId = :videoId AND userId = :userId")
    fun deleteByVideoIdAndUserId(videoId: Int, userId: String)
    
    @Query("DELETE FROM b_favorite_video WHERE userId = :userId")
    fun deleteAllByUserId(userId: String)
} 